<?php

/**
 * @BelongProject: flami_mangers
 * @Author: Zwc
 * @CreateTime: 2025-10-19 15:20:12
 * @Description: TODO
 */

namespace app\admin\logic;

use app\admin\model\AgreementModel;
use think\db\exception\DbException;
use think\Paginator;

class AgreementLogic
{

    private $agreementType = [
        [
            'type' => 'privacyPolicy',
            'name' => '隐私协议'
        ],
        [
            'type' => 'serviceAgreement',
            'name' => '服务协议'
        ],
        [
            'type' => 'userAgreement',
            'name' => '用户协议'
        ],
        [
            'type' => 'aboutUs',
            'name' => '关于我们'
        ],
        [
            'type' => 'recharge',
            'name' => '充值协议'
        ],
        [
            'type' => 'unsubscribe',
            'name' => '注销说明'
        ],
        [
            'type' => 'laborUnion',
            'name' => '公会签约说明'
        ]

    ];

    /**
     *
     * @param $params
     * @return Paginator
     * @throws DbException
     */
    public function getData($params): \think\Paginator
    {
        $condition = [
            'del_flag' => 0
        ];
        if (!empty($params['langId'])) {
            $condition['lang_id'] = $params['langId'];
        }
        $model = new AgreementModel();
        $query = $model->where($condition);

        $list = $query->order("id desc")
            ->paginate(20);

        $agreementTypeMap = array_column($this->agreementType, 'name','type');

        foreach ($list as $k => &$v) {
            if (isset($agreementTypeMap[$v['type']])) {
                $v['typeName'] = $agreementTypeMap[$v['type']];
            }
        }

        return $list;
    }

    /**
     * 获取协议类型
     * @return array[]
     */
    public function getAgreementType(): array
    {
        return $this->agreementType;
    }



}